package com.third.clock.ui.model.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.third.clock.R;
import com.third.clock.bean.ReportEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/23 0023.
 */

public class InBoxAdapter extends RecyclerView.Adapter<InBoxAdapter.ViewHolder> {

    private Context context;

    private List<ReportEntity> list=new ArrayList<>();

    public InBoxAdapter(Context context){
        this.context = context;
    }

    public void setList(List<ReportEntity> list){
        if(list!=null){
            this.list.clear();
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }

    public void addList(List<ReportEntity> list){
        if(list!=null){
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }

    public void remove(int position){
        if(list!=null&&list.size()>position){
            list.remove(position);
            notifyDataSetChanged();
        }
    }

    public ReportEntity getEntity(int position){
        if(list!=null&&list.size()>position){
           return list.get(position);
        }
        return null;
    }

    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_inbox_layout,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        ReportEntity reportEntity=list.get(position);
        if(reportEntity!=null){
            String title=reportEntity.getTitle();
            String cdate=reportEntity.getCdate();
            String content=reportEntity.getContent();
            if(title!=null){
                holder.mTextViewTitle.setText(title);
            }
            if(cdate!=null){
                holder.mTextViewTime.setText(cdate);
            }
            if(content!=null){
                holder.mTextViewContent.setText(content);
            }
        }

    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView mTextViewTitle;

        private TextView mTextViewTime;

        private TextView mTextViewContent;

        public ViewHolder(View itemView) {
            super(itemView);
            mTextViewTitle = (TextView) itemView.findViewById(R.id.text_title);
            mTextViewTime = (TextView) itemView.findViewById(R.id.text_time);
            mTextViewContent = (TextView) itemView.findViewById(R.id.text_content);

        }
    }



}
